package com.ball.dev.service.impl;

import com.ball.common.dtos.ResponseResult;
import com.ball.common.enums.AppHttpCodeEnum;
import com.ball.common.utils.BeanUtils;
import com.ball.common.utils.CollUtils;
import com.ball.dev.entity.po.Jersey;
import com.ball.dev.entity.vo.JerseyVo;
import com.ball.dev.mapper.JerseyMapper;
import com.ball.dev.service.IJerseyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 球衣模版表 服务实现类
 * </p>
 *
 * @author lou
 * @since 2024-04-10
 */
@Service
public class JerseyServiceImpl extends ServiceImpl<JerseyMapper, Jersey> implements IJerseyService {

    @Override
    public ResponseResult addJersey(Jersey jersey) {
        // 判断jersey是否为空
        if (jersey == null){
            // 如果为空，返回参数无效的错误信息
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID,"参数不合法");
        }


        // 调用save方法，添加jersey
        return save(jersey) ?
                // 如果添加成功，返回添加成功的信息
                ResponseResult.okResult("添加成功")
                // 如果添加失败，返回添加失败的错误信息
                : ResponseResult.errorResult(AppHttpCodeEnum.NEED_ADMIND,"添加失败");
    }

    @Override
   public ResponseResult getJerseyList() {

        //查询所有球衣模版，并按照热度倒序排列
        List<Jersey> jerseys = lambdaQuery().orderByDesc(Jersey::getHeat).list();
        //如果查询结果为空，则返回暂无球衣模版
        if (CollUtils.isEmpty(jerseys)){
            return ResponseResult.okResult("暂无球衣模版");
        }

        //将查询结果转换为JerseyVo类型
        List<JerseyVo> jerseyVos = BeanUtils.copyList(jerseys, JerseyVo.class);
        //返回查询结果
        return ResponseResult.okResult(jerseyVos);
    }
}
